#    Based on make file of mhddfs - Multi HDD [FUSE] File System
#    Copyright (C) 2008 Dmitry E. Oboukhov <dimka@avanto.org>

#  This program is free software: you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation, either version 3 of the License, or
#  (at your option) any later version.

#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.

#  You should have received a copy of the GNU General Public License
#  along with this program.  If not, see <http://www.gnu.org/licenses/>.

SRC	=	$(wildcard src/*.c src/isofs/*.c)

OBJ	=	$(SRC:src/%.c=obj/%.o)

DEPS	=	$(OBJ:obj/%.o=obj/%.d)

TARGET	=	appshell

CFLAGS	=	-Wall $(shell pkg-config fuse glib-2.0 zlib --cflags) \
			-DFUSE_USE_VERSION=26 -MMD
ifdef WITHOUT_XATTR
CFLAGS	+=	-DWITHOUT_XATTR
endif

LDFLAGS	=	$(shell pkg-config fuse glib-2.0 zlib --libs)
LDFLAGS	+=	-lm  # For ceil(3)

DESTDIR=
PREFIX=/usr
LIBDIR=${PREFIX}/lib
BINDIR=${PREFIX}/bin
DATADIR=${PREFIX}/share

all: $(TARGET)

$(TARGET): obj/obj-stamp $(OBJ)
	gcc $(CFLAGS) $(OBJ) -o $@ $(LDFLAGS)

obj/obj-stamp:
	mkdir -p obj/isofs
	touch $@

obj/%.o: src/%.c
	gcc $(CFLAGS) -c $< -o $@

clean:
	rm -fr obj $(TARGET)

install: $(TARGET)
	mkdir -p ${DESTDIR}${LIBDIR}/appshell/
	install scripts/identifier.py ${DESTDIR}${LIBDIR}/appshell/
	cp -rf template ${DESTDIR}${LIBDIR}/appshell/
	sed -i "s|@@LIBDIR@@|${LIBDIR}/appshell|g" ${DESTDIR}${LIBDIR}/appshell/identifier.py
	chmod a+x ${DESTDIR}${LIBDIR}/appshell/identifier.py
	chmod a+x ${DESTDIR}${LIBDIR}/appshell/template/exec.*
	mkdir -p ${DESTDIR}${BINDIR}/
	install appshell ${DESTDIR}${BINDIR}/
	install scripts/appshell_build ${DESTDIR}${BINDIR}/
	install scripts/appshell_conv ${DESTDIR}${BINDIR}/
	sed -i "s|@@LIBDIR@@|${LIBDIR}/appshell|g" ${DESTDIR}${BINDIR}/appshell_build \
	${DESTDIR}${BINDIR}/appshell_conv
	chmod a+x ${DESTDIR}${BINDIR}/appshell_build
	chmod a+x ${DESTDIR}${BINDIR}/appshell_conv
	mkdir -p ${DESTDIR}/${DATADIR}/mime/packages
	install data/appshell.xml ${DESTDIR}/${DATADIR}/mime/packages/
	mkdir -p ${DESTDIR}/${DATADIR}/icons/hicolor/scalable/mimetypes
	install data/application-x-appshell.svg ${DESTDIR}/${DATADIR}/icons/hicolor/scalable/mimetypes/

.PHONY: all clean

include $(wildcard obj/*.d)

